import { prisma } from '@/lib/prisma';
import { DestinationCard } from '../DestinationCard';

async function searchDestinations(query: string) {
  return await prisma.destination.findMany({
    where: {
      OR: [
        { name: { contains: query, mode: 'insensitive' } },
        { description: { contains: query, mode: 'insensitive' } },
      ],
    },
    take: 20,
  });
}

export default async function SearchPage({
  searchParams,
}: {
  searchParams: { q: string };
}) {
  const destinations = await searchDestinations(searchParams.q || '');

  return (
    <div className="max-w-7xl mx-auto py-8 px-4 sm:px-6 lg:px-8">
      <h1 className="text-3xl font-bold mb-8">
        搜索结果: {searchParams.q}
      </h1>
      <div className="grid gap-6 md:grid-cols-2 lg:grid-cols-3">
        {destinations.map((destination) => (
          <DestinationCard key={destination.id} destination={destination} />
        ))}
        {destinations.length === 0 && (
          <div className="col-span-full text-center py-12 bg-gray-50 rounded-lg">
            <p className="text-gray-500">没有找到相关目的地</p>
          </div>
        )}
      </div>
    </div>
  );
} 